package test.http;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 获取http路径地址
 * @author microdsyKoal
 * @date 2018年7月3日
 */
public class GetPath extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public GetPath() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	    //     1
	    System.out.println("1" + request.getContextPath());
//      C:\Users\microdsy\git\PRTA_KSSO\WebContent
        System.out.println(request.getSession().getServletContext().getRealPath(""));
//      C:\Users\microdsy\git\PRTA_KSSO\WebContent\
        System.out.println(request.getSession().getServletContext().getRealPath("/"));
//      C:\Users\microdsy\git\PRTA_KSSO\WebContent\caDriver
        System.out.println(request.getSession().getServletContext().getRealPath("/caDriver"));
//      C:\Users\microdsy\git\PRTA_KSSO\WebContent\caDriver
        System.out.println(request.getSession().getServletContext().getRealPath("/caDriver/"));
//      C:\Users\microdsy\git\PRTA_KSSO\WebContent\caDrivercrl.crl
        System.out.println(request.getSession().getServletContext().getRealPath("/caDriver/") + "crl.crl");
//      C:\Users\microdsy\git\PRTA_KSSO\WebContent\caDriver\crl.crl
        System.out.println(request.getSession().getServletContext().getRealPath("/caDriver") + File.separator + "crl.crl");
//      /C:/Users/microdsy/git/PRTA_KSSO/bin/
        System.out.println(this.getClass().getClassLoader().getResource("").getPath());
//      /C:/Users/microdsy/git/PRTA_KSSO/bin/../WebContent/
        System.out.println(this.getClass().getClassLoader().getResource("").getPath()+"../WebContent/");
//      /C:/Users/microdsy/git/PRTA_KSSO/bin/../WebContent/crlcache\crl.crl
        System.out.println(this.getClass().getClassLoader().getResource("").getPath()+"../WebContent/" + File.separator + "crl.crl");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}